package simulatorUS;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map.Entry;
import java.util.Set;

public abstract class SystemEventHandler {
	protected HashMap<String, SystemCommandExecutor> executorsHashMap;
	protected HashMap<String, SystemCommand> commandsHashMap; 
	SystemEventHandler(){
		executorsHashMap =new HashMap<String, SystemCommandExecutor>(5);
	   commandsHashMap = new HashMap<String, SystemCommand>(5);
	}

	public void eventOccured(SystemEvent event) {
	}
	public void SendCommandsFromMap()
	{
		Set<Entry<String, SystemCommand>> set = commandsHashMap.entrySet();
		Iterator<Entry<String, SystemCommand>> iterator = set.iterator();
		while(iterator.hasNext())
		{
			Entry<String, SystemCommand> entry =iterator.next();
			SendCommand(entry.getKey(),entry.getValue());
		}
		commandsHashMap.clear();
	}

	public void SendCommand(String executorName, SystemCommand syscomm) {
		executorsHashMap.get(executorName).execute(syscomm);
	}

	public void addCommandExecutor(String name, SystemCommandExecutor executor) {
		executorsHashMap.put(name, executor);
	}

	public void removeCommandExecutor(String name) {
		executorsHashMap.remove(name);
	}

}
